package day0226;

import java.util.Arrays;
import java.util.Random;

public class Test5 {
    public static void main(String[] args){
        String[]   cards = { "红桃A", "红桃2", "红桃3", "红桃4", "红桃5","红桃6","红桃7",
                "红桃8","红桃9","红桃10","红桃J", "红桃Q", "红桃K" };
        //String[]   result =shffle(cards);//打乱后的这一副牌
        String[]   person1 = new String[4];
        String[]   person2 = new String[4];
        String[]   person3 = new String[4];
        giveThreePerson(cards,person1,person2,person3);
    }//13*4=52       54        留下三张。

    //4
    static void giveThreePerson(String[] result1,String[] p1,String[] p2,String[] p3){
        int index=0;
        for (int i = 0; i < 4; i++) {
            p1[i]=result1[index++];
            p2[i]=result1[index++];
            p3[i]=result1[index++];
            System.out.println();
        }

        /*for (int i = 0; i < result1.length-1; i=i+3) {
            p1[i%4]=result1[i];
            p2[i%4]=result1[i+1];
            p3[i%4]=result1[i+2];
            System.out.println();
        }*/
        System.out.println(Arrays.toString(p1));
        System.out.println(Arrays.toString(p2));
        System.out.println(Arrays.toString(p3));
    }





    public static String[] shffle(String [] cards2){
        String[]   rsCards =new String[cards2.length];
        Random r=new Random();
        for (int i = 0; i < cards2.length; ) {
            int index= r.nextInt(cards2.length);//[0,cards.length)
            if(rsCards[index] == null){
                rsCards[index]=cards2[i];
            }else{
                continue;//不能让i自增， 从cards中还要取出这一张牌，再尝试放入到rsCards数组中
            }   //直到成功的cards[i]放入到rsCards数组中 才能让i自增(换cards下一张牌放入到rsCards数组中)
            i++;
        }
        return rsCards;
    }
}







//